class CreditRecord < ActiveRecord::Base
  before_create :upcase_citizen_id
	has_many :evidences
	belongs_to :user

	paginates_per 10

  validates :industry, presence: true
  validates :person_reported_against, presence: true
  validates :citizen_id, presence: true
  validates :reported_reason, presence: true
  validates :time_of_incident, presence: true

  include Workflow
  workflow do
    state :new do
      event :approve, :transitions_to => :approved
      event :reject, :transitions_to => :rejected
    end
    state :approved
    state :rejected
  end

  def readable_state

    sstate = ''
    if self.current_state == 'new'
      sstate = '等待审核'
    elsif self.current_state == 'approved'
      sstate = '审核通过'
    elsif self.current_state == 'rejected'
      sstate = '审核不通过'
    end
    sstate
  end

  def approve
    
  end

  def reject
    
  end

  def workflow_state_class
    
    sstate = ''
    if self.current_state == 'new'
      sstate = 'label-warning'
    elsif self.current_state == 'approved'
      sstate = 'label-success'
    elsif self.current_state == 'rejected'
      sstate = 'label-default'
    end
    sstate
  end

	def reporter
		self.user
	end
	
  def reporter_realname
    self.user.realname
  end
protected
	def upcase_citizen_id
		self.citizen_id = self.citizen_id.upcase
	end

end
